package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.user.UserDo;
import com.qk.dto.user.UserDTO;
import com.qk.entity.User;
import com.qk.management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Just、倾城
 * @date 2025-10-07
 * @Description no
 * @Version 1.0
 */
@RestController//@Controller + @ResponseBody
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/role/{roleLabel}")
    public Result listByRole(@PathVariable String roleLabel){
        List<User> list = userService.listByRole(roleLabel);
        return Result.success(list);
    }
    @PutMapping
    public Result update(@RequestBody User user){
        userService.update(user);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getUserById(@PathVariable Integer id){
        return Result.success(userService.getUserById(id));
    }
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        userService.deleteBatch(ids);
        return Result.success();
    }
    @GetMapping
    public Result list(UserDTO dto){
        PageResult<UserDo> pageResult = userService.list(dto);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result add(@RequestBody User user){
        userService.add(user);
        return Result.success();
    }

}
